<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Reranker Framework (ReFr): perceptron-model.H Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Reranker Framework (ReFr)
   
   </div>
   <div id="projectbrief">Reranking framework for structure prediction and discriminative language modeling</div>
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">perceptron-model.H</div>  </div>
</div><!--header-->
<div class="contents">
<a href="perceptron-model_8_h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright 2012, Google Inc.</span>
<a name="l00002"></a>00002 <span class="comment">// All rights reserved.</span>
<a name="l00003"></a>00003 <span class="comment">//</span>
<a name="l00004"></a>00004 <span class="comment">// Redistribution and use in source and binary forms, with or without</span>
<a name="l00005"></a>00005 <span class="comment">// modification, are permitted provided that the following conditions are</span>
<a name="l00006"></a>00006 <span class="comment">// met:</span>
<a name="l00007"></a>00007 <span class="comment">//</span>
<a name="l00008"></a>00008 <span class="comment">//   * Redistributions of source code must retain the above copyright</span>
<a name="l00009"></a>00009 <span class="comment">//     notice, this list of conditions and the following disclaimer.</span>
<a name="l00010"></a>00010 <span class="comment">//   * Redistributions in binary form must reproduce the above</span>
<a name="l00011"></a>00011 <span class="comment">//     copyright notice, this list of conditions and the following disclaimer</span>
<a name="l00012"></a>00012 <span class="comment">//     in the documentation and/or other materials provided with the</span>
<a name="l00013"></a>00013 <span class="comment">//     distribution.</span>
<a name="l00014"></a>00014 <span class="comment">//   * Neither the name of Google Inc. nor the names of its</span>
<a name="l00015"></a>00015 <span class="comment">//     contributors may be used to endorse or promote products derived from</span>
<a name="l00016"></a>00016 <span class="comment">//     this software without specific prior written permission.</span>
<a name="l00017"></a>00017 <span class="comment">//</span>
<a name="l00018"></a>00018 <span class="comment">// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS</span>
<a name="l00019"></a>00019 <span class="comment">// &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</span>
<a name="l00020"></a>00020 <span class="comment">// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR</span>
<a name="l00021"></a>00021 <span class="comment">// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT</span>
<a name="l00022"></a>00022 <span class="comment">// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
<a name="l00023"></a>00023 <span class="comment">// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT</span>
<a name="l00024"></a>00024 <span class="comment">// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,</span>
<a name="l00025"></a>00025 <span class="comment">// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY</span>
<a name="l00026"></a>00026 <span class="comment">// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span>
<a name="l00027"></a>00027 <span class="comment">// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE</span>
<a name="l00028"></a>00028 <span class="comment">// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<a name="l00029"></a>00029 <span class="comment">// -----------------------------------------------------------------------------</span>
<a name="l00030"></a>00030 <span class="comment">//</span>
<a name="l00031"></a>00031 <span class="comment">//</span>
<a name="l00035"></a>00035 <span class="comment"></span>
<a name="l00036"></a>00036 <span class="preprocessor">#ifndef RERANKER_PERCEPTRON_MODEL_H_</span>
<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#define RERANKER_PERCEPTRON_MODEL_H_</span>
<a name="l00038"></a>00038 <span class="preprocessor"></span>
<a name="l00039"></a>00039 <span class="preprocessor">#include &lt;vector&gt;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include &lt;tr1/unordered_set&gt;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &lt;tr1/memory&gt;</span>
<a name="l00042"></a>00042 
<a name="l00043"></a>00043 <span class="preprocessor">#include &quot;<a class="code" href="candidate-set_8_h.html" title="Class to hold a single training instance for a reranker, which is a set of examples, typically the n-best output of some input process, posibly including a gold-standard feature vector.">candidate-set.H</a>&quot;</span>
<a name="l00044"></a>00044 <span class="preprocessor">#include &quot;<a class="code" href="dot-product_8_h.html" title="Provides a dot product implementation of the reranker::KernelFunction interface.">dot-product.H</a>&quot;</span>
<a name="l00045"></a>00045 <span class="preprocessor">#include &quot;<a class="code" href="model_8_h.html" title="Reranker model interface.">model.H</a>&quot;</span>
<a name="l00046"></a>00046 <span class="preprocessor">#include &quot;<a class="code" href="training-time_8_h.html" title="Provides the reranker::Time class, which holds the three notions of training time: current epoch...">training-time.H</a>&quot;</span>
<a name="l00047"></a>00047 <span class="preprocessor">#include &quot;<a class="code" href="training-vector-set_8_h.html" title="Provides the reranker::TrainingVectorSet class.">training-vector-set.H</a>&quot;</span>
<a name="l00048"></a>00048 
<a name="l00049"></a><a class="code" href="perceptron-model_8_h.html#a351e6a70fe3295c7beb4b92a5b0b3dfc">00049</a> <span class="preprocessor">#define DEFAULT_MAX_EPOCHS_IN_DECLINE 5</span>
<a name="l00050"></a>00050 <span class="preprocessor"></span>
<a name="l00051"></a>00051 <span class="keyword">namespace </span>reranker {
<a name="l00052"></a>00052 
<a name="l00053"></a>00053 <span class="keyword">using</span> std::tr1::shared_ptr;
<a name="l00054"></a>00054 <span class="keyword">using</span> std::tr1::unordered_set;
<a name="l00055"></a>00055 <span class="keyword">using</span> std::vector;
<a name="l00056"></a>00056 
<a name="l00063"></a><a class="code" href="classreranker_1_1_perceptron_model.html">00063</a> <span class="keyword">class </span><a class="code" href="classreranker_1_1_perceptron_model.html" title="This class implements a perceptron model reranker.">PerceptronModel</a> : <span class="keyword">public</span> <a class="code" href="classreranker_1_1_model.html" title="Model is an interface for reranking models.">Model</a> {
<a name="l00064"></a>00064  <span class="keyword">public</span>:
<a name="l00065"></a><a class="code" href="classreranker_1_1_perceptron_model.html#afb6ec9e4be1c64e078cadea26f2a3b8b">00065</a>   <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classreranker_1_1_perceptron_model_proto_writer.html" title="A class to construct a ModelMessage from a PerceptronModel instance.">PerceptronModelProtoWriter</a>;
<a name="l00066"></a><a class="code" href="classreranker_1_1_perceptron_model.html#af5282652b1f0ee34453543af00f8cee1">00066</a>   <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classreranker_1_1_perceptron_model_proto_reader.html" title="A class to construct a PerceptronModel from a ModelMessage instance.">PerceptronModelProtoReader</a>;
<a name="l00067"></a>00067 
<a name="l00070"></a><a class="code" href="classreranker_1_1_perceptron_model.html#a336a923d8970480c4d0448aa59690891">00070</a>   <a class="code" href="classreranker_1_1_perceptron_model.html#a336a923d8970480c4d0448aa59690891" title="Constructs a new instance with the empty string for its name and the DotProduct kernel function...">PerceptronModel</a>() :
<a name="l00071"></a>00071       <a class="code" href="classreranker_1_1_model.html" title="Model is an interface for reranking models.">Model</a>(<span class="stringliteral">&quot;&quot;</span>, new <a class="code" href="classreranker_1_1_dot_product.html" title="This class defines a dot product kernel function for two vectors.">DotProduct</a>()),
<a name="l00072"></a>00072       <a class="code" href="classreranker_1_1_perceptron_model.html#a6f913688d02fe624d91d1416c71e157c" title="The feature vectors representing this model.">models_</a>(),
<a name="l00073"></a>00073       <a class="code" href="classreranker_1_1_perceptron_model.html#a234283287d5a7f59fd8a1d1cf767fbc1" title="The best models seen so far during training, according to evaluation on the held-out development test...">best_models_</a>(),
<a name="l00074"></a>00074       <a class="code" href="classreranker_1_1_perceptron_model.html#acc08b37db0b4b7ea4cd8d340a4e86216" title="The epoch of the best models seen so far during training.">best_model_epoch_</a>(-1),
<a name="l00075"></a>00075       <a class="code" href="classreranker_1_1_perceptron_model.html#ad2d89585eec1b54986043d6f29a516c3" title="The maximum number of training epochs to keep training after the model starts to degrade (i...">max_epochs_in_decline_</a>(<a class="code" href="perceptron-model_8_h.html#a351e6a70fe3295c7beb4b92a5b0b3dfc">DEFAULT_MAX_EPOCHS_IN_DECLINE</a>),
<a name="l00076"></a>00076       <a class="code" href="classreranker_1_1_perceptron_model.html#a0c25e67c7e7e5cef36bbc1b1fb1cd111" title="The current number of training epochs in which the model has been degrading in development set perfor...">num_epochs_in_decline_</a>(0),
<a name="l00077"></a>00077       <a class="code" href="classreranker_1_1_perceptron_model.html#af852ec770ce5135acbf6f5db34b9d4fc" title="The last value computed by the ComputeStepSize method.">step_size_</a>(1.0) {
<a name="l00078"></a>00078     <a class="code" href="classreranker_1_1_perceptron_model.html#aaed9bda6087a09387988a3def2c90279">SetDefaultObjects</a>();
<a name="l00079"></a>00079   }
<a name="l00080"></a>00080 
<a name="l00085"></a><a class="code" href="classreranker_1_1_perceptron_model.html#a8a67d3c789e5ec7966fedacf51e9d05b">00085</a>   <a class="code" href="classreranker_1_1_perceptron_model.html#a336a923d8970480c4d0448aa59690891" title="Constructs a new instance with the empty string for its name and the DotProduct kernel function...">PerceptronModel</a>(<span class="keyword">const</span> <span class="keywordtype">string</span> &amp;<a class="code" href="classreranker_1_1_model.html#a7360b45e4a024759cd393b376209cf3c" title="Returns the unique name for this model instance.">name</a>) :
<a name="l00086"></a>00086       <a class="code" href="classreranker_1_1_model.html" title="Model is an interface for reranking models.">Model</a>(name, new <a class="code" href="classreranker_1_1_dot_product.html" title="This class defines a dot product kernel function for two vectors.">DotProduct</a>()),
<a name="l00087"></a>00087       <a class="code" href="classreranker_1_1_perceptron_model.html#a6f913688d02fe624d91d1416c71e157c" title="The feature vectors representing this model.">models_</a>(),
<a name="l00088"></a>00088       <a class="code" href="classreranker_1_1_perceptron_model.html#a234283287d5a7f59fd8a1d1cf767fbc1" title="The best models seen so far during training, according to evaluation on the held-out development test...">best_models_</a>(),
<a name="l00089"></a>00089       <a class="code" href="classreranker_1_1_perceptron_model.html#acc08b37db0b4b7ea4cd8d340a4e86216" title="The epoch of the best models seen so far during training.">best_model_epoch_</a>(-1),
<a name="l00090"></a>00090       <a class="code" href="classreranker_1_1_perceptron_model.html#ad2d89585eec1b54986043d6f29a516c3" title="The maximum number of training epochs to keep training after the model starts to degrade (i...">max_epochs_in_decline_</a>(<a class="code" href="perceptron-model_8_h.html#a351e6a70fe3295c7beb4b92a5b0b3dfc">DEFAULT_MAX_EPOCHS_IN_DECLINE</a>),
<a name="l00091"></a>00091       <a class="code" href="classreranker_1_1_perceptron_model.html#a0c25e67c7e7e5cef36bbc1b1fb1cd111" title="The current number of training epochs in which the model has been degrading in development set perfor...">num_epochs_in_decline_</a>(0),
<a name="l00092"></a>00092       <a class="code" href="classreranker_1_1_perceptron_model.html#af852ec770ce5135acbf6f5db34b9d4fc" title="The last value computed by the ComputeStepSize method.">step_size_</a>(1.0) {
<a name="l00093"></a>00093     <a class="code" href="classreranker_1_1_perceptron_model.html#aaed9bda6087a09387988a3def2c90279">SetDefaultObjects</a>();
<a name="l00094"></a>00094   }
<a name="l00095"></a>00095 
<a name="l00101"></a><a class="code" href="classreranker_1_1_perceptron_model.html#a61ec640749f9704d06ba489d6c94fd01">00101</a>   <a class="code" href="classreranker_1_1_perceptron_model.html#a336a923d8970480c4d0448aa59690891" title="Constructs a new instance with the empty string for its name and the DotProduct kernel function...">PerceptronModel</a>(<span class="keyword">const</span> <span class="keywordtype">string</span> &amp;<a class="code" href="classreranker_1_1_model.html#a7360b45e4a024759cd393b376209cf3c" title="Returns the unique name for this model instance.">name</a>, <a class="code" href="classreranker_1_1_kernel_function.html" title="An interface specifying a kernel function for two FeatureVector instances.">KernelFunction</a> *kernel_fn) :
<a name="l00102"></a>00102       <a class="code" href="classreranker_1_1_model.html" title="Model is an interface for reranking models.">Model</a>(name, kernel_fn),
<a name="l00103"></a>00103       <a class="code" href="classreranker_1_1_perceptron_model.html#a6f913688d02fe624d91d1416c71e157c" title="The feature vectors representing this model.">models_</a>(),
<a name="l00104"></a>00104       <a class="code" href="classreranker_1_1_perceptron_model.html#a234283287d5a7f59fd8a1d1cf767fbc1" title="The best models seen so far during training, according to evaluation on the held-out development test...">best_models_</a>(),
<a name="l00105"></a>00105       <a class="code" href="classreranker_1_1_perceptron_model.html#acc08b37db0b4b7ea4cd8d340a4e86216" title="The epoch of the best models seen so far during training.">best_model_epoch_</a>(-1),
<a name="l00106"></a>00106       <a class="code" href="classreranker_1_1_perceptron_model.html#ad2d89585eec1b54986043d6f29a516c3" title="The maximum number of training epochs to keep training after the model starts to degrade (i...">max_epochs_in_decline_</a>(<a class="code" href="perceptron-model_8_h.html#a351e6a70fe3295c7beb4b92a5b0b3dfc">DEFAULT_MAX_EPOCHS_IN_DECLINE</a>),
<a name="l00107"></a>00107       <a class="code" href="classreranker_1_1_perceptron_model.html#a0c25e67c7e7e5cef36bbc1b1fb1cd111" title="The current number of training epochs in which the model has been degrading in development set perfor...">num_epochs_in_decline_</a>(0),
<a name="l00108"></a>00108       <a class="code" href="classreranker_1_1_perceptron_model.html#af852ec770ce5135acbf6f5db34b9d4fc" title="The last value computed by the ComputeStepSize method.">step_size_</a>(1.0) {
<a name="l00109"></a>00109     <a class="code" href="classreranker_1_1_perceptron_model.html#aaed9bda6087a09387988a3def2c90279">SetDefaultObjects</a>();
<a name="l00110"></a>00110   }
<a name="l00111"></a>00111 
<a name="l00120"></a><a class="code" href="classreranker_1_1_perceptron_model.html#ae5c2c4b2680e2be00fdf037e322e1a72">00120</a>   <a class="code" href="classreranker_1_1_perceptron_model.html#a336a923d8970480c4d0448aa59690891" title="Constructs a new instance with the empty string for its name and the DotProduct kernel function...">PerceptronModel</a>(<span class="keyword">const</span> <span class="keywordtype">string</span> &amp;<a class="code" href="classreranker_1_1_model.html#a7360b45e4a024759cd393b376209cf3c" title="Returns the unique name for this model instance.">name</a>, <a class="code" href="classreranker_1_1_kernel_function.html" title="An interface specifying a kernel function for two FeatureVector instances.">KernelFunction</a> *kernel_fn,
<a name="l00121"></a>00121                   <a class="code" href="classreranker_1_1_symbols.html" title="An interface specifying a converter from symbols (strings) to int indices.">Symbols</a> *<a class="code" href="classreranker_1_1_model.html#a736bec0b8f468285580982df181a7cd0" title="Returns the symbol table for this model.">symbols</a>) :
<a name="l00122"></a>00122       <a class="code" href="classreranker_1_1_model.html" title="Model is an interface for reranking models.">Model</a>(name, kernel_fn, symbols),
<a name="l00123"></a>00123       <a class="code" href="classreranker_1_1_perceptron_model.html#a6f913688d02fe624d91d1416c71e157c" title="The feature vectors representing this model.">models_</a>(),
<a name="l00124"></a>00124       <a class="code" href="classreranker_1_1_perceptron_model.html#a234283287d5a7f59fd8a1d1cf767fbc1" title="The best models seen so far during training, according to evaluation on the held-out development test...">best_models_</a>(),
<a name="l00125"></a>00125       <a class="code" href="classreranker_1_1_perceptron_model.html#acc08b37db0b4b7ea4cd8d340a4e86216" title="The epoch of the best models seen so far during training.">best_model_epoch_</a>(-1),
<a name="l00126"></a>00126       <a class="code" href="classreranker_1_1_perceptron_model.html#ad2d89585eec1b54986043d6f29a516c3" title="The maximum number of training epochs to keep training after the model starts to degrade (i...">max_epochs_in_decline_</a>(<a class="code" href="perceptron-model_8_h.html#a351e6a70fe3295c7beb4b92a5b0b3dfc">DEFAULT_MAX_EPOCHS_IN_DECLINE</a>),
<a name="l00127"></a>00127       <a class="code" href="classreranker_1_1_perceptron_model.html#a0c25e67c7e7e5cef36bbc1b1fb1cd111" title="The current number of training epochs in which the model has been degrading in development set perfor...">num_epochs_in_decline_</a>(0),
<a name="l00128"></a>00128       <a class="code" href="classreranker_1_1_perceptron_model.html#af852ec770ce5135acbf6f5db34b9d4fc" title="The last value computed by the ComputeStepSize method.">step_size_</a>(1.0) {
<a name="l00129"></a>00129     <a class="code" href="classreranker_1_1_perceptron_model.html#aaed9bda6087a09387988a3def2c90279">SetDefaultObjects</a>();
<a name="l00130"></a>00130   }
<a name="l00131"></a>00131 
<a name="l00132"></a>00132 
<a name="l00134"></a><a class="code" href="classreranker_1_1_perceptron_model.html#a22ff6d5b2151e1f5111d65bdbb98590a">00134</a>   <span class="keyword">virtual</span> <a class="code" href="classreranker_1_1_perceptron_model.html#a22ff6d5b2151e1f5111d65bdbb98590a" title="Destroys this perceptron model and all its data members.">~PerceptronModel</a>() { }
<a name="l00135"></a>00135 
<a name="l00142"></a><a class="code" href="classreranker_1_1_perceptron_model_1_1_default_update_predicate.html">00142</a>   <span class="keyword">class </span><a class="code" href="classreranker_1_1_perceptron_model_1_1_default_update_predicate.html" title="The default update predicate for perceptron and perceptron-style models, which indicates to do a mode...">DefaultUpdatePredicate</a> : <span class="keyword">public</span> <a class="code" href="classreranker_1_1_model.html" title="Model is an interface for reranking models.">Model</a>::<a class="code" href="classreranker_1_1_model_1_1_update_predicate.html" title="An inner interface for a predicate that tests whether a Model needs to be updated based on the curren...">UpdatePredicate</a> {
<a name="l00150"></a>00150     <span class="keyword">virtual</span> <span class="keywordtype">bool</span> NeedToUpdate(<a class="code" href="classreranker_1_1_model.html" title="Model is an interface for reranking models.">Model</a> *model, <a class="code" href="classreranker_1_1_candidate_set.html" title="A class to hold a set of candidates, either for training or test.">CandidateSet</a> &amp;example);
<a name="l00151"></a>00151   };
<a name="l00152"></a>00152 
<a name="l00171"></a><a class="code" href="classreranker_1_1_perceptron_model_1_1_default_updater.html">00171</a>   <span class="keyword">class </span><a class="code" href="classreranker_1_1_perceptron_model_1_1_default_updater.html" title="The default update function for perceptron models.">DefaultUpdater</a> : <span class="keyword">public</span> <a class="code" href="classreranker_1_1_model.html" title="Model is an interface for reranking models.">Model</a>::<a class="code" href="classreranker_1_1_model_1_1_updater.html" title="An inner interface specifying an update function for a model.">Updater</a> {
<a name="l00172"></a>00172     <span class="keyword">virtual</span> <span class="keywordtype">void</span> Update(<a class="code" href="classreranker_1_1_model.html" title="Model is an interface for reranking models.">Model</a> *m, <a class="code" href="classreranker_1_1_candidate_set.html" title="A class to hold a set of candidates, either for training or test.">CandidateSet</a> &amp;example);
<a name="l00173"></a>00173   };
<a name="l00174"></a>00174 
<a name="l00176"></a><a class="code" href="classreranker_1_1_perceptron_model.html#a80c863f01106f5721971324d8f23bc76">00176</a>   <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;<a class="code" href="classreranker_1_1_perceptron_model.html#a80c863f01106f5721971324d8f23bc76">model_spec</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classreranker_1_1_perceptron_model.html#ae18957d720914dd4bd4528f3de5b282d">model_spec_</a>; }
<a name="l00177"></a>00177 
<a name="l00179"></a><a class="code" href="classreranker_1_1_perceptron_model.html#ac91dd3431ca9a536b7e31db72d052207">00179</a>   <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;<a class="code" href="classreranker_1_1_perceptron_model.html#ac91dd3431ca9a536b7e31db72d052207">proto_reader_spec</a>()<span class="keyword"> const </span>{
<a name="l00180"></a>00180     <span class="keywordflow">return</span> <a class="code" href="classreranker_1_1_perceptron_model.html#a78beef8fe9344050187f176230f52a0b" title="A string that specifies to construct a PerceptronModelProtoReader, which is capable of de-serializing...">proto_reader_spec_</a>;
<a name="l00181"></a>00181   }
<a name="l00182"></a>00182 
<a name="l00184"></a><a class="code" href="classreranker_1_1_perceptron_model.html#a11c4a5013286e6fd465c1dac494f3bcb">00184</a>   <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;<a class="code" href="classreranker_1_1_perceptron_model.html#a11c4a5013286e6fd465c1dac494f3bcb">proto_writer_spec</a>()<span class="keyword"> const </span>{
<a name="l00185"></a>00185     <span class="keywordflow">return</span> <a class="code" href="classreranker_1_1_perceptron_model.html#a2fcf5e3e8dbb2c0f731509d1af9230c0" title="A string that specifies to construct a PerceptronModelProtoWriter, which is capable of serializing an...">proto_writer_spec_</a>;
<a name="l00186"></a>00186   }
<a name="l00187"></a>00187 
<a name="l00190"></a><a class="code" href="classreranker_1_1_perceptron_model.html#afae11bd9b41855ae74cf974fdf1ef417">00190</a>   <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classreranker_1_1_perceptron_model.html#afae11bd9b41855ae74cf974fdf1ef417" title="Returns the epoch of the best models seen so far during training.">best_model_epoch</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classreranker_1_1_perceptron_model.html#acc08b37db0b4b7ea4cd8d340a4e86216" title="The epoch of the best models seen so far during training.">best_model_epoch_</a>; }
<a name="l00191"></a>00191 
<a name="l00256"></a>00256   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classreranker_1_1_perceptron_model.html#aa2ce4f882d64528ae8e8daba60a54d3f" title="Registers several variables that may be initialized when this object is constructed via Factory::Crea...">RegisterInitializers</a>(<a class="code" href="classreranker_1_1_initializers.html" title="A container for all the member initializers for a particular Factory-constructible instance...">Initializers</a> &amp;initializers);
<a name="l00257"></a>00257 
<a name="l00260"></a>00260   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classreranker_1_1_perceptron_model.html#ae2972c3b76402f2bafc6938984025090" title="Initializes this instance.">Init</a>(<span class="keyword">const</span> <span class="keywordtype">string</span> &amp;arg);
<a name="l00261"></a>00261 
<a name="l00262"></a>00262   <span class="comment">// training methods</span>
<a name="l00263"></a>00263 
<a name="l00264"></a>00264   <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classreranker_1_1_perceptron_model.html#a089a2268c88e89684c03d0730c5691c7" title="Returns whether more training epochs are required for this model.">NeedToKeepTraining</a>();
<a name="l00265"></a>00265 
<a name="l00278"></a>00278   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classreranker_1_1_perceptron_model.html#a8ccab23af92f9a7db985257791f55acb" title="Trains this model on a collection of training examples, where each training example is a set of candi...">Train</a>(<a class="code" href="classreranker_1_1_candidate_set_iterator.html" title="An interface specifying iteration over CandidateSet instances, using Java-style semantics (sorry...">CandidateSetIterator</a> &amp;examples,
<a name="l00279"></a>00279                      <a class="code" href="classreranker_1_1_candidate_set_iterator.html" title="An interface specifying iteration over CandidateSet instances, using Java-style semantics (sorry...">CandidateSetIterator</a> &amp;development_test);
<a name="l00280"></a>00280 
<a name="l00281"></a>00281   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classreranker_1_1_perceptron_model.html#a598e88d61b4b35b2b5df59a00fc73d6e">NewEpoch</a>();
<a name="l00282"></a>00282 
<a name="l00283"></a>00283   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classreranker_1_1_perceptron_model.html#a5e1359da40c7d987f2a14b7b47765a83">EndOfEpoch</a>();
<a name="l00284"></a>00284 
<a name="l00290"></a>00290   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classreranker_1_1_perceptron_model.html#ae88557a6953807829c8d5fb760589487" title="Trains this model for one epoch, i.e., a single pass through the specified set of training examples...">TrainOneEpoch</a>(<a class="code" href="classreranker_1_1_candidate_set_iterator.html" title="An interface specifying iteration over CandidateSet instances, using Java-style semantics (sorry...">CandidateSetIterator</a> &amp;examples);
<a name="l00291"></a>00291 
<a name="l00295"></a>00295   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classreranker_1_1_perceptron_model.html#abfb9261016f61a8f660e699ccbdafa6a" title="Trains this model on the specified training example.">TrainOnExample</a>(<a class="code" href="classreranker_1_1_candidate_set.html" title="A class to hold a set of candidates, either for training or test.">CandidateSet</a> &amp;example);
<a name="l00296"></a>00296 
<a name="l00302"></a>00302   <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classreranker_1_1_perceptron_model.html#a2d1e5450a8d1ccc781b9b135b7504a3f" title="Indicates whether the current model needs to be updated; the implementation here simply returns true ...">NeedToUpdate</a>(<a class="code" href="classreranker_1_1_candidate_set.html" title="A class to hold a set of candidates, either for training or test.">CandidateSet</a> &amp;example);
<a name="l00303"></a>00303 
<a name="l00309"></a>00309   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classreranker_1_1_perceptron_model.html#ae7e3982866cc3db145c0e3ff4b6ef783" title="Updates the current model based on the specified set of candidates.">Update</a>(<a class="code" href="classreranker_1_1_candidate_set.html" title="A class to hold a set of candidates, either for training or test.">CandidateSet</a> &amp;example);
<a name="l00310"></a>00310 
<a name="l00312"></a>00312   <span class="keyword">virtual</span> <span class="keywordtype">double</span> <a class="code" href="classreranker_1_1_perceptron_model.html#a615950ed57b7ea2c729b374438f8d31e">Evaluate</a>(<a class="code" href="classreranker_1_1_candidate_set_iterator.html" title="An interface specifying iteration over CandidateSet instances, using Java-style semantics (sorry...">CandidateSetIterator</a> &amp;development_test);
<a name="l00313"></a>00313 
<a name="l00326"></a>00326   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classreranker_1_1_perceptron_model.html#ace55bad139573080e682d5a269760673" title="Scores the specified set of candidates according to either the raw or averaged version of this percep...">ScoreCandidates</a>(<a class="code" href="classreranker_1_1_candidate_set.html" title="A class to hold a set of candidates, either for training or test.">CandidateSet</a> &amp;candidates, <span class="keywordtype">bool</span> training);
<a name="l00327"></a>00327 
<a name="l00337"></a>00337   <span class="keyword">virtual</span> <span class="keywordtype">double</span> <a class="code" href="classreranker_1_1_perceptron_model.html#aff26021ce19337a90068b66a219c0c6c" title="Scores a candidate according to either the raw or averaged version of this perceptron model...">ScoreCandidate</a>(<a class="code" href="classreranker_1_1_candidate.html" title="A class to represent a candidate in a set of candidates that constitutes a training instance for a re...">Candidate</a> &amp;candidate, <span class="keywordtype">bool</span> training);
<a name="l00338"></a>00338 
<a name="l00339"></a>00339   <span class="comment">// mutators</span>
<a name="l00340"></a>00340 
<a name="l00342"></a>00342   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classreranker_1_1_perceptron_model.html#a919a86a6a3a52f62199b438fb092836d">CompactifyFeatureUids</a>();
<a name="l00343"></a>00343   
<a name="l00347"></a><a class="code" href="classreranker_1_1_perceptron_model.html#aad31b03949457cdabffdc4d2d9cefeaa">00347</a>   <span class="keywordtype">void</span> <a class="code" href="classreranker_1_1_perceptron_model.html#aad31b03949457cdabffdc4d2d9cefeaa" title="Sets the maximum number of training epochs to keep training after the model starts to degrade (i...">set_max_epochs_in_decline</a>(<span class="keywordtype">int</span> max_epochs_in_decline) {
<a name="l00348"></a>00348     <a class="code" href="classreranker_1_1_perceptron_model.html#ad2d89585eec1b54986043d6f29a516c3" title="The maximum number of training epochs to keep training after the model starts to degrade (i...">max_epochs_in_decline_</a> = max_epochs_in_decline;
<a name="l00349"></a>00349   }
<a name="l00350"></a>00350 
<a name="l00353"></a><a class="code" href="classreranker_1_1_perceptron_model.html#acc78df07e227da7761f05f75abba1144">00353</a>   <span class="keyword">virtual</span> <span class="keyword">const</span> <a class="code" href="classreranker_1_1_training_vector_set.html" title="A class to hold the several feature vectors needed during training (especially for the perceptron fam...">TrainingVectorSet</a> &amp;<a class="code" href="classreranker_1_1_perceptron_model.html#acc78df07e227da7761f05f75abba1144" title="Returns the set of models and statistics used by this PerceptronModel instance.">models</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classreranker_1_1_perceptron_model.html#a6f913688d02fe624d91d1416c71e157c" title="The feature vectors representing this model.">models_</a>; }
<a name="l00354"></a>00354 
<a name="l00355"></a>00355  <span class="keyword">protected</span>:
<a name="l00356"></a><a class="code" href="classreranker_1_1_perceptron_model.html#aaed9bda6087a09387988a3def2c90279">00356</a>   <span class="keywordtype">void</span> <a class="code" href="classreranker_1_1_perceptron_model.html#aaed9bda6087a09387988a3def2c90279">SetDefaultObjects</a>() {
<a name="l00357"></a>00357     <a class="code" href="classreranker_1_1_model.html#aac9c10b6d6a3eec5f781cfbf64bcdf22" title="The update predicate for this model.">update_predicate_</a> =
<a name="l00358"></a>00358         <a class="code" href="classreranker_1_1_model.html#a1f79bda31ef5b3ed236d77a79403d789">GetUpdatePredicate</a>(<span class="stringliteral">&quot;PerceptronModelDefaultUpdatePredicate()&quot;</span>);
<a name="l00359"></a>00359     <a class="code" href="classreranker_1_1_model.html#a6af75a0de0ab2cfb3435919977341550" title="The updater for this model.">updater_</a> =
<a name="l00360"></a>00360         <a class="code" href="classreranker_1_1_model.html#a66309617d0bdc5a615d843b2ae88e9d8">GetUpdater</a>(<span class="stringliteral">&quot;PerceptronModelDefaultUpdater()&quot;</span>);
<a name="l00361"></a>00361   }
<a name="l00362"></a>00362 
<a name="l00379"></a>00379   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classreranker_1_1_perceptron_model.html#af7b4bb2f10d16bcc6bdf2428e6c09af3" title="Computes the features to be updated for the gold candidate and the best-scoring candidate.">ComputeFeaturesToUpdate</a>(<span class="keyword">const</span> <a class="code" href="classreranker_1_1_candidate_set.html" title="A class to hold a set of candidates, either for training or test.">CandidateSet</a> &amp;example,
<a name="l00380"></a>00380                                        unordered_set&lt;int&gt; &amp;
<a name="l00381"></a>00381                                        gold_features_to_update,
<a name="l00382"></a>00382                                        unordered_set&lt;int&gt; &amp;
<a name="l00383"></a>00383                                        best_scoring_features_to_update) <span class="keyword">const</span>;
<a name="l00384"></a>00384 
<a name="l00389"></a><a class="code" href="classreranker_1_1_perceptron_model.html#a64bdfab86dd1ea94c4918d409e2cd5d9">00389</a>   <span class="keyword">virtual</span> <span class="keywordtype">double</span> <a class="code" href="classreranker_1_1_perceptron_model.html#a64bdfab86dd1ea94c4918d409e2cd5d9" title="Computes the step size for the next update, and, as a side effect, caches this value in step_size_...">ComputeStepSize</a>(<span class="keyword">const</span> unordered_set&lt;int&gt; &amp;gold_features,
<a name="l00390"></a>00390                                <span class="keyword">const</span> unordered_set&lt;int&gt; &amp;best_scoring_features,
<a name="l00391"></a>00391                                <span class="keyword">const</span> <a class="code" href="classreranker_1_1_candidate_set.html" title="A class to hold a set of candidates, either for training or test.">CandidateSet</a> &amp;example) {
<a name="l00392"></a>00392     <span class="keywordflow">return</span> <a class="code" href="classreranker_1_1_perceptron_model.html#af852ec770ce5135acbf6f5db34b9d4fc" title="The last value computed by the ComputeStepSize method.">step_size_</a>;
<a name="l00393"></a>00393     <span class="comment">// For MIRA, simply derive class and override to be</span>
<a name="l00394"></a>00394     <span class="comment">/*</span>
<a name="l00395"></a>00395 <span class="comment">    int feature_count = gold_features.size() + best_scoring_features.size();</span>
<a name="l00396"></a>00396 <span class="comment">    double loss_diff =</span>
<a name="l00397"></a>00397 <span class="comment">      example.GetBestScoring().loss() - example.GetGold().loss();</span>
<a name="l00398"></a>00398 <span class="comment">    double score_diff =</span>
<a name="l00399"></a>00399 <span class="comment">      example.GetBestScoring().score() - example.GetGold().score();</span>
<a name="l00400"></a>00400 <span class="comment">    double raw_step = (loss_diff + score_diff) / feature_count;</span>
<a name="l00401"></a>00401 <span class="comment">    step_size_ = raw_step &gt; mira_clip_ : mira_clip_ : raw_step;</span>
<a name="l00402"></a>00402 <span class="comment">    return step_size_;</span>
<a name="l00403"></a>00403 <span class="comment">    */</span>
<a name="l00404"></a>00404   }
<a name="l00405"></a>00405 
<a name="l00406"></a>00406   <span class="comment">// data members</span>
<a name="l00408"></a><a class="code" href="classreranker_1_1_perceptron_model.html#a6f913688d02fe624d91d1416c71e157c">00408</a> <span class="comment"></span>  <a class="code" href="classreranker_1_1_training_vector_set.html" title="A class to hold the several feature vectors needed during training (especially for the perceptron fam...">TrainingVectorSet</a> <a class="code" href="classreranker_1_1_perceptron_model.html#a6f913688d02fe624d91d1416c71e157c" title="The feature vectors representing this model.">models_</a>;
<a name="l00411"></a><a class="code" href="classreranker_1_1_perceptron_model.html#a234283287d5a7f59fd8a1d1cf767fbc1">00411</a>   <a class="code" href="classreranker_1_1_training_vector_set.html" title="A class to hold the several feature vectors needed during training (especially for the perceptron fam...">TrainingVectorSet</a> <a class="code" href="classreranker_1_1_perceptron_model.html#a234283287d5a7f59fd8a1d1cf767fbc1" title="The best models seen so far during training, according to evaluation on the held-out development test...">best_models_</a>;
<a name="l00413"></a><a class="code" href="classreranker_1_1_perceptron_model.html#acc08b37db0b4b7ea4cd8d340a4e86216">00413</a>   <span class="keywordtype">int</span> <a class="code" href="classreranker_1_1_perceptron_model.html#acc08b37db0b4b7ea4cd8d340a4e86216" title="The epoch of the best models seen so far during training.">best_model_epoch_</a>;
<a name="l00416"></a><a class="code" href="classreranker_1_1_perceptron_model.html#ad2d89585eec1b54986043d6f29a516c3">00416</a>   <span class="keywordtype">int</span> <a class="code" href="classreranker_1_1_perceptron_model.html#ad2d89585eec1b54986043d6f29a516c3" title="The maximum number of training epochs to keep training after the model starts to degrade (i...">max_epochs_in_decline_</a>;
<a name="l00420"></a><a class="code" href="classreranker_1_1_perceptron_model.html#a0c25e67c7e7e5cef36bbc1b1fb1cd111">00420</a>   <span class="keywordtype">int</span> <a class="code" href="classreranker_1_1_perceptron_model.html#a0c25e67c7e7e5cef36bbc1b1fb1cd111" title="The current number of training epochs in which the model has been degrading in development set perfor...">num_epochs_in_decline_</a>;
<a name="l00422"></a><a class="code" href="classreranker_1_1_perceptron_model.html#af852ec770ce5135acbf6f5db34b9d4fc">00422</a>   <span class="keywordtype">double</span> <a class="code" href="classreranker_1_1_perceptron_model.html#af852ec770ce5135acbf6f5db34b9d4fc" title="The last value computed by the ComputeStepSize method.">step_size_</a>;
<a name="l00423"></a><a class="code" href="classreranker_1_1_perceptron_model.html#ae18957d720914dd4bd4528f3de5b282d">00423</a>   <span class="keywordtype">string</span> <a class="code" href="classreranker_1_1_perceptron_model.html#ae18957d720914dd4bd4528f3de5b282d">model_spec_</a>;
<a name="l00424"></a>00424 
<a name="l00428"></a><a class="code" href="classreranker_1_1_perceptron_model.html#a78beef8fe9344050187f176230f52a0b">00428</a>   <span class="keyword">static</span> <span class="keywordtype">string</span> <a class="code" href="classreranker_1_1_perceptron_model.html#a78beef8fe9344050187f176230f52a0b" title="A string that specifies to construct a PerceptronModelProtoReader, which is capable of de-serializing...">proto_reader_spec_</a>;
<a name="l00432"></a><a class="code" href="classreranker_1_1_perceptron_model.html#a2fcf5e3e8dbb2c0f731509d1af9230c0">00432</a>   <span class="keyword">static</span> <span class="keywordtype">string</span> <a class="code" href="classreranker_1_1_perceptron_model.html#a2fcf5e3e8dbb2c0f731509d1af9230c0" title="A string that specifies to construct a PerceptronModelProtoWriter, which is capable of serializing an...">proto_writer_spec_</a>;
<a name="l00433"></a>00433 };
<a name="l00434"></a>00434 
<a name="l00435"></a>00435 }  <span class="comment">// namespace reranker</span>
<a name="l00436"></a>00436 
<a name="l00437"></a>00437 <span class="preprocessor">#endif</span>
</pre></div></div><!-- contents -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Tue Apr 9 2013 11:56:29 for Reranker Framework (ReFr) by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
